package timer;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Timer类的缺陷问题
 */
public class TimerDefect {
    private static long start;
    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerTask timerTask1 = new TimerTask() {
            @Override
            public void run() {
                System.out.println(" timerTask1 "+(System.currentTimeMillis()-start));
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        TimerTask timerTask2 = new TimerTask() {
            @Override
            public void run() {
                System.out.println(" timerTask2 "+(System.currentTimeMillis()-start));
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        start = System.currentTimeMillis();
        timer.schedule(timerTask1,1000,1000);
//        timer.schedule(timerTask2,3000); 900 1800
    }
}
